package com.thinktank.controller;

import java.io.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import com.oreilly.servlet.*;
import com.oreilly.servlet.multipart.*;

public class UploadProcessController implements Controller {

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws IOException, ServletException {
		// 파일 업로드 기본 세팅
		ServletContext sc = request.getServletContext();
		String path = sc.getRealPath("\\upload");
		String encType = "utf-8";
		int maxSize = 5 * 1024 * 1024;
		File targetDir = new File(path);
		if (!targetDir.exists())
			targetDir.mkdirs();

		MultipartRequest multi = new MultipartRequest(request, path, maxSize,
				encType, new DefaultFileRenamePolicy());
		Enumeration formNames=multi.getFileNames();
		
		while(formNames.hasMoreElements()){
			String formName=(String)formNames.nextElement();
			String fileName = multi.getFilesystemName(formName);
			String originalFileName=multi.getOriginalFileName(formName);
			if(fileName != null){
				System.out.println("폼 이름 : " + formName);
				System.out.println("파일 이름 : " + fileName);
				System.out.println("오리 이름 : " + originalFileName);
			}
		}
		return null;
	}

}
